package com.example.myapplication.ui.home;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;

public class CourseDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course_detail);

        // 获取传递的课程ID
        String courseId = getIntent().getStringExtra("courseId");

        // 设置默认值，防止courseId为null
        if (courseId == null) {
            courseId = "1";
        }

        // 模拟从网络获取详情
        CourseDetail detail = new CourseDetail();

        if ("1".equals(courseId)) {
            detail.setTitle("Android开发入门-详情");
            detail.setImageUrl("https://img95.699pic.com/xsj/10/1v/5k.jpg");
            detail.setInstructor("张老师（资深Android工程师）");
            detail.setDifficulty("初级");
            detail.setRating(4.8f);
            detail.setDesc("本课程从基础开始，讲解Android开发全流程，包含Activity、Fragment、网络请求等核心知识点...");
            detail.setContent("课程章节：\n1. Android开发环境搭建\n2. 第一个HelloWorld应用\n3. 界面布局与控件使用\n4. 网络请求与数据解析...");
        } else if ("2".equals(courseId)) {
            detail.setTitle("Java基础实战-详情");
            detail.setImageUrl("https://img95.699pic.com/xsj/07/2c/8i.jpg");
            detail.setInstructor("李老师（10年Java开发经验）");
            detail.setDifficulty("入门");
            detail.setRating(4.6f);
            detail.setDesc("从零学习Java语法、面向对象、集合框架，通过实战案例掌握核心技能...");
            detail.setContent("课程章节：\n1. Java语法基础\n2. 面向对象编程\n3. 集合框架与泛型\n4. IO流与多线程...");
        } else if ("3".equals(courseId)) {
            detail.setTitle("UI设计原理-详情");
            detail.setImageUrl("https://img95.699pic.com/xsj/0s/6b/2b.jpg");
            detail.setInstructor("王老师（资深UI设计师）");
            detail.setDifficulty("中级");
            detail.setRating(4.9f);
            detail.setDesc("学习UI设计规范、色彩搭配、交互逻辑，打造专业UI设计作品...");
            detail.setContent("课程章节：\n1. UI设计基础理论\n2. 色彩与排版设计\n3. 交互与动效设计\n4. 实战项目：电商APP界面设计...");
        } else if ("4".equals(courseId)) {
            detail.setTitle("Python入门到精通-详情");
            detail.setImageUrl("https://img95.699pic.com/xsj/01/9s/3b.jpg");
            detail.setInstructor("赵老师（Python领域专家）");
            detail.setDifficulty("初级");
            detail.setRating(4.7f);
            detail.setDesc("掌握Python语法、数据分析、爬虫等实用技能，实战驱动快速掌握核心能力...");
            detail.setContent("课程章节：\n1. Python基础语法\n2. 数据结构与函数\n3. 数据分析与可视化\n4. 网络爬虫实战...");
        } else {
            // 默认课程
            detail.setTitle("课程详情");
            detail.setImageUrl("https://img95.699pic.com/xsj/10/1v/5k.jpg");
            detail.setInstructor("未知老师");
            detail.setDifficulty("未知");
            detail.setRating(0f);
            detail.setDesc("课程详情加载中...");
            detail.setContent("课程内容加载中...");
        }

        // 绑定UI展示详情
        ImageView ivImage = findViewById(R.id.ivDetailImage);
        TextView tvTitle = findViewById(R.id.tvDetailTitle);
        TextView tvInstructor = findViewById(R.id.tvDetailInstructor);
        TextView tvDifficulty = findViewById(R.id.tvDetailDifficulty);
        TextView tvRating = findViewById(R.id.tvDetailRating);
        TextView tvDesc = findViewById(R.id.tvDetailDesc);
        TextView tvContent = findViewById(R.id.tvDetailContent);
        Button btnBack = findViewById(R.id.btnBack);

        Glide.with(this).load(detail.getImageUrl()).into(ivImage);
        tvTitle.setText(detail.getTitle());
        tvInstructor.setText("讲师：" + detail.getInstructor());
        tvDifficulty.setText("难度：" + detail.getDifficulty());
        tvRating.setText("评分：" + detail.getRating());
        tvDesc.setText(detail.getDesc());
        tvContent.setText(detail.getContent());

        // 返回按钮点击事件
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish(); // 关闭当前Activity，返回首页
            }
        });
    }
}